#include "../liolib/lioflat.h"

class WinInfo:public FlatApplication
{
	int i,j,k;
	float ax,ay,az;
	DWORD updates,messages;

	BOOL create();
	void update();
	void draw2D();
} info;

BOOL WinInfo::create()
{
	FlatApplication::create();
	name=_T("GL WinInfo");
	updates=messages=0;
	setProcessPriority(HIGH_PRIORITY_CLASS);
	screen.zNearOrtho=0;
	screen.zFarOrtho=400;
	ax=60;
	az=30;
	ay=0;
	return TRUE;
}
void WinInfo::update()
{
	updates++;
	if (keyboard.keys [VK_ESCAPE])
	{
		terminate();
	}
	if (keyboard.keys [VK_F1])
	{
		toggleFullscreen();	
		keyboard.keys [VK_F1] = FALSE;
	}
	if (keyboard.keys ['Q'])
	{
		ax++;
	}
	else if(keyboard.keys ['W'])
	{
		ax--;
	}
	if (keyboard.keys ['A'])
	{
		ay++;
	}
	else if(keyboard.keys ['S'])
	{
		ay--;
	}
	if (keyboard.keys ['Z'])
	{
		az++;
	}
	else if(keyboard.keys ['X'])
	{
		az--;
	}
	if(keyboard.keys [VK_SPACE])
	{
		ax=ay=az=0;
	}
	setUpdated(TRUE);
}

void WinInfo::draw2D()
{
	setColor(INT_WHITE);
	drawLineIndicator(
			10.0f,10.0f,10.0f,float(window.height-20),
			float(1000*loopTime/24),2.0f,DIR_UP,
			INT_GREEN,INT_YELLOW,INT_RED,
			INT_WHITE,INT_BLACK);

	font.x=30;
	font.color=INT_WGRAY;
	font.y=15;
	font.y+=18;
	glPrint(&font,_T("process priority:       0x%08X"),getProcessPriority());
	font.y+=18;
	glPrint(&font,_T("updates:                %06d"), updates);
	font.y+=18;
	glPrint(&font,_T("loop:                   %.2f ms"),1e3*loopTime);
	font.y+=18;
	glPrint(&font,_T("refresh rate:           %.2f"), INV(loopTime));
	font.y+=18;
	glPrint(&font,_T("avg refresh rate:       %.1f"), float(updates)/runTime);
	font.y+=18;
	glPrint(&font,_T("window width:           %04d"), window.width);
	font.y+=18;
	glPrint(&font,_T("height height:          %04d"), window.height);
	font.y+=18;
	glPrint(&font,_T("bits per pixel:         %d"), display.bpp);

	font.y+=18;
	glPrint(&font,_T("global event count:     %06d"), msgCount);
	font.y+=18;
	glPrint(&font,_T("event message:          0x%03X"), msg.message);
	font.y+=18;
	glPrint(&font,_T("keyboard.code:          0x%03X"), keyboard.code);
	font.y+=18;
	glPrint(&font,_T("keyboard.symbol:        %c"), keyboard.symbol);
	font.y+=18;
	glPrint(&font,_T("keyboard.repeatCount:   %d"), keyboard.repeatCount);
	font.y+=18;
	glPrint(&font,_T("keyboard.scanCode:      %d"), keyboard.scanCode);
	font.y+=18;
	glPrint(&font,_T("keyboard.extendKey:     %d"), keyboard.extendKey);
	font.y+=18;
	glPrint(&font,_T("keyboard.alt:           %d"), keyboard.alt);
	font.y+=18;
	glPrint(&font,_T("keyboard.repeated:      %d"), keyboard.repeated);
	font.y+=18;
	glPrint(&font,_T("keyboard.pressed:       %d"), keyboard.pressed);

	font.y+=18;
	glPrint(&font,_T("mouse.x:                %d"), mouse.x);
	font.y+=18;
	glPrint(&font,_T("mouse.y:                %d"), mouse.y);
	font.y+=18;
	glPrint(&font,_T("mouse.wheel:            %d"), mouse.wheel);
	font.y+=18;
	glPrint(&font,_T("mouse.lbutton:          %d"), mouse.lbutton);
	font.y+=18;
	glPrint(&font,_T("mouse.mbutton:          %d"), mouse.mbutton);
	font.y+=18;
	glPrint(&font,_T("mouse.rbutton:          %d"), mouse.rbutton);
	font.y+=18;
	glPrint(&font,_T("mouse.shift:            %d"), mouse.shift);
	font.y+=18;
	glPrint(&font,_T("mouse.ctrl:             %d"), mouse.ctrl);

	setColor(INT_WHITE);
	glTranslatef(400,300,-200);
	glRotate(ax,ay,az);
	drawLine(-50,0,0,50,0,0);
	drawLine(0,-50,0,0,50,0);
	drawLine(0,0,-50,0,0,50);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
	return info.main(hInstance,hPrevInstance,lpCmdLine,nCmdShow);
}